/**
 * Created by Julia on 2016/4/28.
 */

define(['jquery', 'appLocalStorage', 'appMessageBox', 'appConst'], function ($, appLocalStorage, msgBox, appConst) {
    return {
        findGrrItem: function (param, callback, errCallBack) {
            $.ajax({
                url: 'analysis/grr/getGrrItem',
                type: 'POST',
                dataType: 'JSON',
                "data": param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        findPSInfo: function (param, callback, errCallBack) {
            $.ajax({
                url: 'analysis/grr/getPSInfo',
                type: 'POST',
                dataType: 'JSON',
                "data": param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        findSetting: function (param, callback, errCallBack) {
            $.ajax({
                url: 'analysis/grr/getSetting',
                type: 'POST',
                dataType: 'JSON',
                "data": param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message, 'GRR_SETTING');
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        findSlot: function (param, callback, errCallBack) {
            $.ajax({
                url: 'analysis/grr/getSummarySlot',
                type: 'POST',
                dataType: 'JSON',
                "data": param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        findSummary: function (param, callback, errCallBack) {
            $.ajax({
                url: 'analysis/grr/getSummary',
                type: 'POST',
                dataType: 'JSON',
                "data": param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        findAnovaAndSource: function (param, callback, errCallBack) {
            $.ajax({
                url: 'analysis/grr/getAnovaAndSource',
                type: 'POST',
                dataType: 'JSON',
                "data": param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },

        findGrrTestData:function (param, callback, errCallBack) {
            $.ajax({
                url: 'analysis/grr/getGrrTestData',
                type: 'POST',
                dataType: 'JSON',
                "data": param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        saveGrrTestData:function (param, callback, errCallBack) {
            $.ajax({
                url: 'analysis/grr/saveGrrTestData',
                type: 'POST',
                dataType: 'JSON',
                "data": param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        getChoiceTestItem:function (param, callback, errCallBack) {
            $.ajax({
                url: 'analysis/grr/getChoiceTestItem',
                type: 'POST',
                dataType: 'JSON',
                "data": param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        findChartData:function (param, callback, errCallBack) {
            $.ajax({
                url: 'analysis/grr/getChartData',
                type: 'POST',
                dataType: 'JSON',
                "data": param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },

        saveChoiceTestItem:function (param, callback, errCallBack) {
            $.ajax({
                url: 'analysis/grr/saveChoiceTestItem',
                type: 'POST',
                dataType: 'JSON',
                "data": param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        deleteGrrItem:function (param, callback, errCallBack) {
            $.ajax({
                url: 'analysis/grr/deleteGrrItem',
                type: 'POST',
                dataType: 'JSON',
                "data": param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },

        exportGrrDataAll: function (param, callback, errCallBack) {
            $.ajax({
                url: 'export/grr/resultAndData',
                type: "POST",
                dataType: 'json',
                data: param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },

                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        exportGrrDataSummary: function (param, callback, errCallBack) {
            $.ajax({
                url: "export/grr/result",
                type: "POST",
                dataType: 'json',
                data: param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },

                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        refreshGrrSummary: function (param, callback, errCallBack) {
            $.ajax({
                url: "analysis/grr/refreshGrrSummary",
                type: "POST",
                dataType: 'json',
                data: param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },

                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        refreshAnovaAndSource: function (param, callback, errCallBack) {
            $.ajax({
                url: "analysis/grr/refreshGrrResult",
                type: "POST",
                dataType: 'json',
                data: param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },

                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },

        findPSA:function (param, callback, errCallBack) {
            $.ajax({
                url: "project/psa",
                type: "POST",
                dataType: 'json',
                data: param,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },

                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        }
    }
});